<?php

namespace App\Http\Middleware;

use App\Constants\ErrorCode;
use App\Dto\AuthDto;
use App\Exceptions\ServiceException;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class CheckManager
{
    /**
     * 是否是服务商管理员
     * @param Request $request
     * @param Closure $next
     * @return Response
     * @throws ServiceException
     */
    public function handle(Request $request, Closure $next): Response
    {
        if (!is_manager(AuthDto::getUser())) {
            throw new \Exception('not permission!',ErrorCode::CODE_ERROR_403);
        }
        return $next($request);
    }
}
